<?php
session_start();
die("FAIL ! ...sorry...."); // comment this line before starting this script

echo "A warning right <br>HERE -- ";
include("sql/sqlCon.php");
echo "should occur. If it doesn't, something is wrong. Or you have already ran this script.<br><br><br>";

if ( mysql_query("CREATE DATABASE ".$SQLDBName, $con) ) echo "Database $SQLDBName created!<br/>";
else echo "Error creating database $SQLDBName : " . mysql_error() . '<br/>';

mysql_select_db($SQLDBName, $con); 



// basic users table
if(mysql_query("CREATE TABLE $usersTableName(
userId INT UNSIGNED,
userName VARCHAR(55),
sha1Pass VARCHAR(44),
inactive VARCHAR(15)
)")) 
echo "Table $usersTableName created!<br/>";
else echo "Could not create table $usersTableName : ".mysql_error()."<br/>";


// extended users table
if(mysql_query("CREATE TABLE $usersExtendedTableName(
userId INT UNSIGNED,
email VARCHAR(255),
regOn VARCHAR(20),
userLevel TINYINT,
warn TINYINT,
lang VARCHAR(10),
uploadMaxFileSizeKB MEDIUMINT UNSIGNED,
uploadUsedSpaceKB MEDIUMINT UNSIGNED,
uploadGrantedSpaceMB MEDIUMINT,
uploadAllowedTypes VARCHAR(10)
)"))
echo "Table $usersExtendedTableName created!<br/>";
else echo "Could not create table $usersExtendedTableName : ".mysql_error()."<br/>";

// add default admin user.............
// username : admin
// password : changeMeASAP
mysql_query("INSERT INTO $usersTableName (userId, userName, sha1Pass, inactive) 
             VALUES ('0', 'admin', '77abd2d6c7178603f64026555d2720b3b12b426a', '0')");
mysql_query("INSERT INTO $usersExtendedTableName (userId, email, regOn, userLevel, warn, lang, 
												  uploadMaxFileSizeKB, uploadGrantedSpaceMB, uploadUsedSpaceKB, uploadAllowedTypes)  
                     VALUES ('0', 'admin@admin.admin', '".date('j/n/Y, H:i')."', 1, 0, 'en', 
							 0, -1, 0, 'all')");
if( mysql_error() ) echo "Could not create default admin user - ".mysql_error();
else echo "Default admin user created. CHANGE PASSWORD ASAP!<br/>";

// uploader table
if(mysql_query("CREATE TABLE $uploadsTableName(
fileId INT UNSIGNED,
byUserId INT UNSIGNED,
filePath VARCHAR(150),
fileSizeKB MEDIUMINT UNSIGNED,
uploadedDate VARCHAR(20),
isImg TINYINT(1),
isPrivate TINYINT(1),
origFileName VARCHAR(55),
description VARCHAR(155)
)"))
echo "Table $uploadsTableName created!<br/>";
else echo "Could not create table $uploadsTableName : ".mysql_error()."<br/>";


// news CMS table
if(mysql_query("CREATE TABLE $newsCMSTableName(
line int unsigned,
title tinytext,
content text,
postedon tinytext,
discussl tinytext
)")) 
echo "Table $newsCMSTableName created!<br/>";
else echo "Could not create table $newsCMSTableName : ".mysql_error()."<br/>";

?>